package com.hxgis.oc.product.idw;

import com.hxgis.oc.util.idw.IDWConvertor;
import com.hxgis.oc.product.base.ConvertTask;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;
import java.util.function.Function;

@Setter
@Getter
@Slf4j
public class IDWConvTask extends ConvertTask {
    protected Function<File, IDWConvertor> convFunc;

    public IDWConvTask(Long workID, String ds) {
        super(workID, ds);
        productType = IDWProductManager.getFactoryName();
    }

    @Override
    public boolean producing() {
        boolean succeed = false;

        IDWConvertor operation = null;
        try {
            operation = convFunc.apply(inputFile);
            operation.init(outputFile);
            succeed = operation.create();
        } catch (IOException e) {
            log.error(e.getMessage());
        }finally {
            if(operation != null){
                operation.clearTmp();
            }
            if(!succeed){
                retrieve();
            }
        }
        return succeed;
    }
}
